#include<bits/stdc++.h>

using namespace std;

int dp[105][105][105];

signed main() {
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    int _;
    cin >> _;
    while (_--) {
        int n;
        cin >> n;
        memset(dp, -0x3f, sizeof(dp));
        dp[0][0][0] = 0;
        for (int i = 0; i < n; i++) {
            int x;
            cin >> x;
            for (int j = 0; j <= 100; j++)
                for (int k = 0; k <= 100; k++) {
                    dp[i + 1][x][k] = max(dp[i + 1][x][k], dp[i][j][k] + (x == j) * x);
                    dp[i + 1][j][x] = max(dp[i + 1][j][x], dp[i][j][k] + (x == k) * x);
                }
        }
        int ans = 0;
        for (int i = 0; i <= 100; i++)
            for (int j = 0; j <= 100; j++)
                ans = max(ans, dp[n][i][j]);
        cout << ans << endl;
    }
    return 0;
}
